import type { ModelFieldsRow } from '#/views/onlineDesign/designModel/designModel.data';

import { requestClient } from '#/api/request';

export namespace GenModelFieldsTableApi {
  export type RowTypeFetchParams = ModelFieldsRow;
  export interface IdFetchParams {
    id: string;
  }
  export interface ModelFetchParams {
    modelCode: string;
  }
  export interface ListFetchParams {
    [key: string]: any;
  }
  export interface PageListFetchParams {
    [key: string]: any;
    pageNo: number;
    pageSize: number;
  }
}

/**
 * 分页列表查询
 */
export async function genModelFieldsQueryPageListApi(
  params: GenModelFieldsTableApi.PageListFetchParams,
) {
  return requestClient.get('/gen/modelFields/queryPageList', {
    params,
  });
}

/**
 * 列表查询
 */
export async function genModelFieldsQueryListApi(
  params: GenModelFieldsTableApi.ListFetchParams,
) {
  return requestClient.get('/gen/modelFields/queryList', { params });
}

/**
 * 通过ID查询
 * @param params
 */
export async function genModelFieldsQueryByIdApi(
  params: GenModelFieldsTableApi.IdFetchParams,
) {
  return requestClient.get('/gen/modelFields/queryById', { params });
}

/**
 * 新增
 */
export async function genModelFieldsAddApi(
  params: GenModelFieldsTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/gen/modelFields/add', params);
}

/**
 * 编辑
 */
export async function genModelFieldsEditApi(
  params: GenModelFieldsTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/gen/modelFields/edit', params);
}

/**
 * 删除
 * @param id 主键
 */
export async function genModelFieldsDelApi(id) {
  return requestClient.delete<boolean>(`/gen/modelFields/delete/${id}`);
}

/**
 * 批量删除删除
 * @param ids 主键
 */
export async function genModelFieldsDeleteBatchApi(ids) {
  return requestClient.delete<boolean>(
    `/gen/modelFields/deleteBatchByIds/${ids}`,
  );
}

/**
 * 通过模型Code查询字段
 * @param params 模型CODE
 */
export async function genModelFieldsQueryModelFieldsApi(
  params: GenModelFieldsTableApi.ModelFetchParams,
) {
  return requestClient.get('/gen/modelFields/queryModelFields', { params });
}

/**
 * 新增或编辑字段信息
 * @param params
 */
export async function genModelFieldsSaveOrEditApi(
  params: GenModelFieldsTableApi.RowTypeFetchParams,
) {
  return requestClient.post('/gen/modelFields/saveOrEdit', params);
}
